/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package org.prashant.sqlduniya.dashboard;

import java.awt.Component;
import javax.swing.JLabel;
import javax.swing.JList;
import javax.swing.ListCellRenderer;
import org.prashant.sqlduniya.sqlmanager.DBConnectionInfo;

/**
 *
 * @author prashant
 */
public class DBConnectionInfoListRenderer implements ListCellRenderer {

    private final ListCellRenderer delegate;

    public DBConnectionInfoListRenderer(ListCellRenderer delegate) {
        this.delegate = delegate;
    }

    @Override
    public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
        JLabel renderer = (JLabel) delegate.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
        if (value instanceof DBConnectionInfo) {
            String label = ((DBConnectionInfo) value).getName();
            renderer.setText(label);
            if ("New Connection".equalsIgnoreCase(label)) {
                renderer.setIcon(new javax.swing.ImageIcon(getClass().getResource("/org/prashant/sqlduniya/dashboard/newdb-icon16.png")));
            } else {
                renderer.setIcon(new javax.swing.ImageIcon(getClass().getResource("/org/prashant/sqlduniya/dashboard/db-icon16.png")));
            }
        }
        return renderer;
    }
}
